<template lang="pug">
    el-card(shadow="never")
      div(slot="header",class="clearfix")
          span 新增胰岛素品牌

      el-form(:model="newInsulin",ref="newInsulinForm")
        el-form-item(prop="name",:rules="[{required:true, message: '胰岛素泵品牌名称不能为空'}]")
          el-input(placeholder="胰岛素泵品牌名称",v-model="newInsulin.name",type="text",@change="submit")

      div(class="card-footer")
          div(class="pull-right")
              el-button(size="small",@click="resetForm('newInsulinForm')")
                span 重置
              submit-button(@click="submit",:loading="submiting",type="button")
                i(class="el-icon-check")
                span 新建

</template>

<script>
import Vue from "vue";
import { AwesomePagination } from "awesome-element-ui";
Vue.use(AwesomePagination);

import axios from "@/plugin/axios";

import InsulinNewModel from './InsulinNewModel';
import BaseNew from '@/mixins/BaseNew';

export default {
  name: "pump-brand-create",
  mixins:[BaseNew],
  data() {
    return {
      newInsulin: new InsulinNewModel()
    };
  },

  methods: {
   submit(){
     if(this.submiting) return; // 防止重复提交
     this.$refs.newInsulinForm.validate(valid => {
       if(valid) this.doSubmit();
     })
   },
   doSubmit(){
     axios({method: 'post', url: '/PumpBrand/Create', data:{model: this.newInsulin}})
     .then(data=>this.submitSuccess(data))
     .catch(() => (this.submiting = false))
   },
   submitSuccess(data){
     this.submiting = false;
     this.showNewSuccess();
     this.resetForm('newInsulinForm');
     this.$emit('success'); // 提交事件
   }
  },
  created() {
  }
};
</script>
